package com.eling.elcms.community.webapp.controller;

import com.eling.elcms.community.model.Department;
import com.eling.elcms.community.service.IDepartmentManager;
import com.eling.elcms.core.webapp.controller.BaseFormController;
import com.eling.elcms.core.webapp.controller.Msg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
public class DepartmentController extends BaseFormController{
    @Autowired
    private IDepartmentManager departmentManager;
    
    @RequestMapping("/api/department/add")
    @ResponseBody
    public Department add(@ModelAttribute Department department) {
    	department.setSeal(false);
    	return departmentManager.save(department);
    }
    
    @RequestMapping("/api/department/{pkDepartment}/delete")
    @ResponseBody
    public Msg delete(@PathVariable Long pkDepartment) {
    	departmentManager.remove(pkDepartment);
    	return new Msg("删除成功");
    }
    
    @RequestMapping("/api/department/update")
    @ResponseBody
    public Department update(@RequestBody Department department) {
    	return departmentManager.save(department);
    }
   
    //用于其他节点的调用
    @RequestMapping("/api/department/query")
    @ResponseBody
    public List<Department> query(@ModelAttribute Department cond) {
    	cond.setSeal(false);
    	return departmentManager.query(cond);
    }
    
    //用于本节点的调用
    @RequestMapping("/api/department/queryall")
    @ResponseBody
    public List<Department> getAll() {
    	return departmentManager.getAll();
    }
    
    @RequestMapping("/api/department/querynew")
    @ResponseBody
    public List<Department> queryNew(@ModelAttribute Department cond) {
    	return departmentManager.query(cond);
    }
    
    @RequestMapping("/api/department/{pkDepartment}/seal")
    @ResponseBody
    public Department seal(@PathVariable Long pkDepartment) {
    	return departmentManager.seal(pkDepartment);
    }
}
